package com.elibrary;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import com.actionbarsherlock.view.Window;
import nimo.elibrary.db.model.User;
import nimo.elibrary.db.model.UserDataSource;

/**
 * Created with IntelliJ IDEA.
 * User: Enkuso
 * Date: 11/29/12
 * Time: 4:12 PM
 * To change this template use File | Settings | File Templates.
 */
public class Splash extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.splash);

        getSupportActionBar().hide();

        Thread loader = new Thread(){
            @Override
            public void run() {
                super.run();
                BookstoreApplication app = (BookstoreApplication) getApplicationContext();
                try {
                    sleep(2000);
                    // TODO: Load app data here
                    UserDataSource userds = new UserDataSource(BookstoreApplication.getAppContext());
                    User user = userds.getLoggedUser();
                    app.setLoggedIn(user.token);

                } catch (Exception e) {
                    app.setLoggedOut();
                } finally {
                    Intent mainMenu = new Intent("com.elibrary.MAINACTIVITY");
                    startActivity(mainMenu);
                    //gotoBookDetail(new View(app), "1");
                }
            }
        };

        loader.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}
